import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { HttpService } from '../public/service/http.service';
import {
  AbstractControl,
  FormBuilder,
  FormGroup,
  Validators
} from '@angular/forms';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.less']
})
export class LoginComponent implements OnInit {

  validateForm: FormGroup;
  isLogin: boolean = true;

  submitForm(): void {
    //console.log(this.validateForm.value);
    this.service.sendRequest({ url: 'LOGIN' })
      .subscribe(
        data => {
          //console.log(data);
          if (data.INFBDY) {
            let loginData = data.INFBDY.RAMANBSCZ1;
            //console.log(loginData);
            if (loginData[0].status == '1') {
              console.log('登录成功!');
              this.router.navigate(['ntb-home']);

            }
          }else{

          }

        }
      )
  }

  constructor(
    private service: HttpService,
    private fb: FormBuilder,
    private router: Router
  ) {
  }

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      userName: [null, [Validators.required]],
      password: [null, [Validators.required]],
      remember: [true]
    });
  }

}
